import hashlib
from io import BytesIO
import os

def calculate_sha1(file_like_object):
    # 创建一个新的 sha1 哈希对象
    sha1 = hashlib.sha1()
    
    # 读取文件内容并更新哈希对象
    while True:
        data = file_like_object.read(8192)
        if not data:
            break
        sha1.update(data)
    
    # 返回哈希值的十六进制表示
    return sha1.hexdigest()

if __name__ == '__main__':
    # print(calculate_sha1(BytesIO(b'hello world')))

    gradle_src = '.gradle/caches/modules-2/files-2.1/gradle/gradle/8.7/9f40849a65e9eea2dbcdae85d2939684160c146/gradle-8.7-src.zip'

    gradle_src_path = os.path.join(os.getenv('HOME'), gradle_src)

    filememory = BytesIO()
    with open(gradle_src_path, 'rb') as f:
        filememory.write(f.read())

    filememory.seek(0)
    print(calculate_sha1(filememory))